<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *订单管理
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$tabs=array(
	array('op'=>'list','title'=>'收益明细'),
	array('op'=>'listday','title'=>'每日收益统计'),
	array('op'=>'listmonth','title'=>'每月收益统计'),
);
if($_RQ['op']=='list'){
	$return['params']=array();
	if($_RQ['id']){
		$this->session('cangid',$_RQ['id']);
	}
	$cangid=$this->session('cangid');
	$params=array('merchid'=>$merchid,'uniacid'=>$_SESSION['uniacid'],'cangid'=>$cangid);
	if(isset($_RQ['mid'])){
		$params['mid']=intval($_RQ['mid']);
		$return['params']['mid']=intval($_RQ['mid']);
	}
	if(isset($_RQ['paixu'])){
		$yaoid=pdo_getcolumn('jy_mjicai_yao',array('paixu'=>$_RQ['paixu'],'cangid'=>$cangid,'uniacid'=>$_SESSION['uniacid']),'id');
		$params['yaoid']=$yaoid;
		$return['params']['paixu']=intval($_RQ['paixu']);
	}
	$pindex = max(1, intval($_RQ['page']));
	if($_RQ['psize']){
		$_SESSION['psize']=$_RQ['psize'];
	}
	$psize = $_SESSION['psize']?:10;
	$list=pdo_getslice('jy_mjicai_jilog',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as $k=>&$item){
			$item['member']=cfc('core')->member_show($item['mid']);
			$item['paixu']=pdo_getcolumn('jy_mjicai_yao',array('id'=>$item['yaoid'],'uniacid'=>$_SESSION['uniacid']),'paixu');
			$item['paixu']='第【'.$item['paixu'].'】'.$this->y_title;
			$item['status']=pdo_getcolumn('jy_mjicai_yao',array('id'=>$item['yaoid'],'uniacid'=>$_SESSION['uniacid']),'status');
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','total'=>$total,'psize'=>$psize,'edit'=>false,'del_one'=>false,'delall'=>false,'list'=>array(
			array('name'=>'member','title'=>'会员信息_Member','type'=>'member'),
			array('name'=>'paixu','title'=>'第几'.$this->y_title,'type'=>'string'),
			array('name'=>'jifen','title'=>'收益积分','type'=>'string'),
			array('name'=>'status','title'=>'状态','type'=>'radio','options'=>'yao_status'),
			array('name'=>'createtime','title'=>'时间','type'=>'time'),
		)),
		'search'=>array(
			array('name'=>'paixu','width'=>15,'title'=>'第几'.$this->y_title,'type'=>'string'),
			array('type'=>'choose','width'=>15,'action'=>'core/member.get_member/','name'=>'mid','title'=>'选择会员'),
		),
	);
	$return['yao_status']=$this->yao_status;
	$return['htmls']=$htmls;	
	exi($return);
}
if($_RQ['op']=='listday'){
	$cangid=$this->session('cangid');
	$params=array('merchid'=>$merchid,'uniacid'=>$_SESSION['uniacid'],'cangid'=>$cangid);
	$y=$_RQ['y']?:date('Y');
	$m=$_RQ['m']?:date('m');
	if(!empty($_RQ['y'])){
		$return['params']['y']=$_RQ['y'];
	}
	if(!empty($_RQ['m'])){
		$return['params']['m']=$_RQ['m'];
	}
	$daynum=date("t",strtotime($y.'-'.$m));
	$list=array();
	for($i=1;$i<=$daynum;$i++){
		$starttime=strtotime($y.'-'.$m.'-'.$i);
		$endtime=$starttime+24*3600;
		$params['createtime between']=array($starttime,$endtime);
		$fee=pdo_getsum('jy_mjicai_jilog',$params,'jifen');
		$list[]=array(
			'title'=>$y.'-'.$m.'-'.$i,
			'fee'=>$fee,
		);
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','edit'=>false,'del_one'=>false,'delall'=>false,'list'=>array(
			array('name'=>'title','title'=>'日期','type'=>'string'),
			array('name'=>'fee','title'=>'收益积分','type'=>'string'),
		)),
		'search'=>array(
			array('name'=>'y','width'=>15,'title'=>'年份','type'=>'radio','options'=>'ys'),
			array('name'=>'m','width'=>15,'title'=>'月份','type'=>'radio','options'=>'months'),
		)
	);
	$return['htmls']=$htmls;
	$nowy=date('Y');
	$y1=$nowy-2;
	$y2=$nowy-1;
	$return['ys']=array(
		$y1=>$y1.'年',
		$y2=>$y2.'年',
		$nowy=>$nowy.'年',
	);
	$return['months']=array(
		'1'=>'1月',
		'2'=>'2月',
		'3'=>'3月',
		'4'=>'4月',
		'5'=>'5月',
		'6'=>'6月',
		'7'=>'7月',
		'8'=>'8月',
		'9'=>'9月',
		'10'=>'10月',
		'11'=>'11月',
		'12'=>'12月',
	);
	exi($return);
}
if($_RQ['op']=='listmonth'){
	$cangid=$this->session('cangid');
	$params=array('merchid'=>$merchid,'uniacid'=>$_SESSION['uniacid'],'cangid'=>$cangid);
	$y=$_RQ['y']?:date('Y');
	if(!empty($_RQ['y'])){
		$return['params']['y']=$_RQ['y'];
	}
	$list=array();
	for($i=1;$i<=12;$i++){
		$starttime=strtotime($y.'-'.$i);
		if($i==12){
			$ny=$y+1;
			$endtime=strtotime($ny.'-01');
		}else{
			$endtime=strtotime($y.'-'.$m+1);
		}
		$params['createtime between']=array($starttime,$endtime);
		$fee=pdo_getsum('jy_mjicai_jilog',$params,'jifen');
		$list[]=array(
			'title'=>$y.'-'.$i,
			'fee'=>$fee,
		);
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','edit'=>false,'del_one'=>false,'delall'=>false,'list'=>array(
			array('name'=>'title','title'=>'月份','type'=>'string'),
			array('name'=>'fee','title'=>'收益积分','type'=>'string'),
		)),
		'search'=>array(
			array('name'=>'y','width'=>15,'title'=>'年份','type'=>'radio','options'=>'ys'),
		)
	);
	$return['htmls']=$htmls;
	$nowy=date('Y');
	$y1=$nowy-2;
	$y2=$nowy-1;
	$return['ys']=array(
		$y1=>$y1.'年',
		$y2=>$y2.'年',
		$nowy=>$nowy.'年',
	);
	exi($return);
}